import ajax, { ListResult,getQuery } from '../ajax';


export function getList(data:any) {
  return ajax.post<ListResult>(`/ControlPanels/Roles/Query`, data);
}

export function updateEntity(data:any) {
  if (!data.application) {
    data.applicationId = 10;
  }
  
  if(data.roleId) {
    return ajax.put<any>('/ControlPanels/Roles', data);
  } else {
    return ajax.post<any>('/ControlPanels/Roles', data);
  }
}

export function deleteEntity(id:number) {
  let deleteCommand = {"id": id};
  return ajax.put<any>('/ControlPanels/Roles/Actions/Delete', deleteCommand);
}

export function getAppMenus() {
  let data = getQuery('menuId');
  return ajax.post<ListResult>(`/ControlPanels/Menus/Query`, data);
}

export function getRoleMenus(roleId: number) {
  return ajax.get<Array<any>>(`/ControlPanels/Roles/${roleId}/Menus`);
}

export function bindMenu(roleId:number, menuId:number) {
  let data = {
    roleId,
    menuId
  }
  return ajax.post(`/ControlPanels/Roles/Actions/Bind/Menu`, data);
}

export function unbindMenu(roleId:number, menuId:number) {
  let data = {
    roleId,
    menuId
  }
  return ajax.post(`/ControlPanels/Roles/Actions/Unbind/Menu`, data);
}